import 'package:flutter/material.dart';
import 'package:huxiaodui/api/model/alarm_model.dart';
import 'package:huxiaodui/view/pop_pages/alarm_message_list.dart';
import 'package:huxiaodui/view/index/map_page/map_controller.dart';
import 'package:intl/intl.dart';

class AlarmInfoPage extends StatelessWidget {
  const AlarmInfoPage({super.key, required this.alarm});
  final AlarmModel alarm;
  @override
  Widget build(BuildContext context) {
    TextField textField(
        {required Icon icon,
        required String labelText,
        required String content}) {
      TextEditingController controller = TextEditingController();
      controller.text = content;
      return TextField(
        textInputAction: TextInputAction.next,
        autofocus: true,
        readOnly: true,
        controller: controller,
        decoration: InputDecoration(
          prefixIcon: icon,
          labelText: labelText,
        ),
      );
    }

    return Scaffold(
      appBar: AppBar(
        title: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            const Text("报警详情"),
            Row(
              children: [
                Visibility(
                  visible: !alarm.expired,
                  child: IconButton(
                    onPressed: () {
                      MapController().toMarker(alarm);
                    },
                    icon: Icon(Icons.location_on),
                  ),
                ),
                IconButton(
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => AlarmMessageInfos(
                          alarm: alarm,
                        ),
                      ),
                    );
                  },
                  icon: Icon(Icons.add_chart),
                )
              ],
            )
          ],
        ),
      ),
      body: Container(
        padding: const EdgeInsets.all(16),
        child: ListView(
          children: [
            Column(
              children: [
                textField(
                  icon: const Icon(Icons.account_balance),
                  labelText: "报警单位",
                  content: alarm.unit.name,
                ),
                const SizedBox(height: 5),
                textField(
                  icon: const Icon(Icons.merge_type),
                  labelText: "报警类型",
                  content: AlarmModel.typeList[alarm.type],
                ),
                const SizedBox(height: 5),
                textField(
                  icon: const Icon(Icons.access_time),
                  labelText: "报警时间",
                  content: "${DateFormat('yyyy-MM-dd HH:mm:ss').format(alarm.alarmAt)}   [ ${alarm.alarmAtDistanceToString} ]",
                ),
                const SizedBox(height: 5),
                textField(
                  icon: const Icon(Icons.timelapse),
                  labelText: "持续时长",
                  content: alarm.durationToString,
                ),
                const SizedBox(height: 5),
                textField(
                  icon: const Icon(Icons.perm_identity),
                  labelText: "负责人",
                  content: alarm.unit.manager,
                ),
                const SizedBox(height: 5),
                textField(
                  icon: const Icon(Icons.phone),
                  labelText: "联系电话",
                  content: alarm.unit.tel,
                ),
                const SizedBox(height: 5),
                textField(
                  icon: const Icon(Icons.domain_add_rounded),
                  labelText: "地址",
                  content: alarm.unit.addr,
                ),
                const SizedBox(height: 5),
                textField(
                  icon: const Icon(Icons.local_police),
                  labelText: "辖区派出所",
                  content: alarm.unit.policeStation,
                ),
                SizedBox(height: 50),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
